/*
 * @Copyright: 2023 - 2023 www.hoperun.com Inc. All rights reserved.
 */

package com.lifeservice.console.controller;

import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.utils.StringUtils;
import com.lifeservice.console.domain.LifeCityBuilding;
import com.lifeservice.console.domain.LifeService;
import com.lifeservice.console.domain.LifeSupplierInfo;
import com.lifeservice.console.domain.SelectVo;
import com.lifeservice.console.mapper.LifeCityBuildingMapper;
import com.lifeservice.console.mapper.LifeServiceMapper;
import com.lifeservice.console.mapper.LifeSupplierInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author liu_yifeng
 * @function SelectValueController
 * @date 2023/3/6 10:57
 */
@RestController
@RequestMapping("/console/dict")
public class SelectValueController {
    @Autowired
    private LifeCityBuildingMapper buildingMapper;

    @Autowired
    private LifeSupplierInfoMapper lifeSupplierInfoMapper;

    @Autowired
    private LifeServiceMapper lifeServiceMapper;


    @GetMapping("/map")
    public AjaxResult list() {
        SelectVo vo = new SelectVo();
        LifeCityBuilding queryBuilding = new LifeCityBuilding();
        List<LifeCityBuilding> list = buildingMapper.selectLifeCityBuildingList(queryBuilding);
        if (StringUtils.isNotEmpty(list)) {
            Map<String, String> buildingMap = list.stream()
                    .collect(Collectors.toMap(LifeCityBuilding::getId, LifeCityBuilding::getBuildingName));
            vo.setBuildingMap(buildingMap);
        }
        LifeSupplierInfo querySupplier = new LifeSupplierInfo();
        List<LifeSupplierInfo> supplierInfos = lifeSupplierInfoMapper.selectLifeSupplierInfoList(querySupplier);
        if (StringUtils.isNotEmpty(supplierInfos)) {
            Map<String, String> supplierMap = supplierInfos.stream()
                    .collect(Collectors.toMap(LifeSupplierInfo::getId, LifeSupplierInfo::getSupplierName));
            vo.setSupplierMap(supplierMap);
        }
        List<LifeService> services = lifeServiceMapper.selectLifeServiceList(new LifeService());
        if (StringUtils.isNotEmpty(services)) {
            Map<String, String> serviceMap = services.stream()
                    .collect(Collectors.toMap(LifeService::getId, LifeService::getServiceName));
            vo.setServiceMap(serviceMap);
        }
        return AjaxResult.success(vo);
    }
}
